// Shows a clear confirmation
function clearConfirmation(message)
{
    var stringBundle = document.getElementById("webdeveloper-string-bundle");

    return confirmationDialog(stringBundle.getString("clearConfirmation"), message, stringBundle.getString("clear"));
}

// Shows a close confirmation
function closeConfirmation(message)
{
    var stringBundle = document.getElementById("webdeveloper-string-bundle");

    return confirmationDialog(stringBundle.getString("closeConfirmation"), message, stringBundle.getString("close"));
}

// Shows a confirmation dialog
function confirmationDialog(title, message, buttonText)
{
    // If the hide confirmation dialogs preference is not set to true
    if(!getBooleanPreference("webdeveloper.confirmation.dialogs.hide", true))
    {
        var checkBox               = {value: false};
        var promptServiceInterface = Components.interfaces.nsIPromptService;
        var result                 = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(promptServiceInterface).confirmEx(null, title, message, promptServiceInterface.BUTTON_TITLE_IS_STRING * promptServiceInterface.BUTTON_POS_0 + promptServiceInterface.BUTTON_TITLE_CANCEL * promptServiceInterface.BUTTON_POS_1, buttonText, null, null, document.getElementById("webdeveloper-string-bundle").getString("stopConfirmation"), checkBox);

        // If the check box was checked
        if(checkBox.value)
        {
            setBooleanPreference("webdeveloper.confirmation.dialogs.hide", true);
        }

        // If the delete is confirmed
        if(result == 0)
        {
            return true;
        }

        return false;
    }

    return true;
}

// Shows a delete confirmation
function deleteConfirmation(message)
{
    var stringBundle = document.getElementById("webdeveloper-string-bundle");

    return confirmationDialog(stringBundle.getString("deleteConfirmation"), message, stringBundle.getString("delete"));
}

// Shows an error message
function error(message)
{
    Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService).alert(null, document.getElementById("webdeveloper-string-bundle").getString("errorMessage"), message);
}

// Shows an informational dialog
function informationalDialog(title, message)
{
    var checkBox               = {value: false};
    var promptServiceInterface = Components.interfaces.nsIPromptService;
    var stringBundle           = document.getElementById("webdeveloper-string-bundle");
    var result                 = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(promptServiceInterface).alertCheck(null, title, message, stringBundle.getString("stopInformational"), checkBox);

    // If the check box was checked
    if(checkBox.value)
    {
        setBooleanPreference("webdeveloper.informational.dialogs.hide", true);
    }
}

// Shows a message
function message(title, message)
{
    Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService).alert(null, title, message);
}
